package cn.cdeden.knowledge.service;


import cn.cdeden.common.core.domain.R;
import cn.cdeden.common.core.utils.page.TableDataInfo;
import cn.cdeden.knowledge.domain.*;
import cn.cdeden.knowledge.domain.dto.*;
import cn.cdeden.knowledge.domain.vo.PersonalFilesTreeVo;
import cn.cdeden.resource.api.domain.RemoteFilesDownload;
import cn.cdeden.resource.api.domain.RemoteFilesUpload;
import cn.cdeden.system.api.model.LoginUser;
import com.baomidou.mybatisplus.extension.service.IService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
* @author Chen
* @date 2022-09-16
*/
public interface TeamFilesTreeService extends IService<TeamFilesTree> {

    static final String CACHE_KEY = "teamFilesTree";

    /**
    * 查询数据分页
    * @param query 条件
    * @param pageable 分页参数
    * @return PageInfo<TeamFilesTreeDto>
    */
    TableDataInfo<TeamFilesTreeDto> queryAll(TeamFilesTreeQueryParam query, Pageable pageable);

    /**
    * 查询所有数据不分页
    * @param query 条件参数
    * @return List<TeamFilesTreeDto>
    */
    TeamFilesTreeDto queryAll(TeamFilesTreeQueryParam query);

    TeamToEnterpriseDto assembleTeamToEnterprise(String id);

    /**
     * 创建文件夹 如果有重名文件夹将返回重名对象 duplicate值为true
     * @param teamFilesTreeInsertParam
     * @return
     */
    TeamFilesTreeDto createFolder(TeamFilesTreeInsertParam teamFilesTreeInsertParam, String userId);

    /**
     *
     * @param path 需要创建的路径
     * @param parentId 指定的上级文件夹（可以为null）
     * @param teamId 团队Id
     * @param userId 创建人Id
     * @return 所有路径id集合
     */
    Long insertByPath(String path,String parentId,String teamId,String userId);

    List<TeamFilesTreeDto> selectAll(String parentId);

    TeamFilesTree getById(Long id);
    TeamFilesTreeDto findById(Long id);
    List<FilesTree> selectFilesTree(Collection<String> ids);

    /**
     *
     * @param teamFilesTreeDtos 数据
     * @param userId 用户id
     * @param roleType 不等于的角色类型
     * @return
     */
    List<TeamFilesTreeDto> removeNotPermTree(List<TeamFilesTreeDto> teamFilesTreeDtos,Long userId,String roleType);

    TeamFilesTreeDto selectTeamTree(String id);

    /**
     * 查询所有下级目录
     * @param id
     * @return
     */
    List<TeamFilesTree> selectJuniorAll(String id);
    List<TeamFilesTree> selectJuniorAll(List<String> ids, String deleteType);

    /**
     * @author Yu.
     * @Description // 判断是否是自己的文件夹
     * @Date 2024/8/14 16:17
     * @param nodeId
     * @param teamId 团队编号
     * @param b
     * @return boolean
     **/
    boolean selectByNodeIdIsOwn(List<String> nodeId,String teamId,boolean b);




    /**
     * 查询所有上级目录
     * @param id
     * @return
     */
    List<TeamFilesTree> selectSuperiorAll(String id);


    /**
     * @author Yu.
     * @Description // 可以下载和预览 文件夹 下的全部儿子文件 是否删除
     * @Date 2023/11/22 13:54
     * @param ids
     * @param b
     * @return java.util.List<com.cdyd.ecm.domain.TreeDownloadFiles> 返回文件消息
     **/
    List<RemoteFilesDownload> folderSonFiles(List<String> ids, Boolean b, String userId);



    boolean rename(TeamFilesTreeDto teamFilesTreeDto);

    R fileTreeCopy(RecoverFileChooseAPath chooseAPath);
    R fileTreeMove(RecoverFileChooseAPath chooseAPath);

    @Transactional(rollbackFor = Exception.class)
    TeamFilesTree insert(TeamFilesTreeDto teamFilesTreeDto);

    @Transactional(rollbackFor = Exception.class)
    TeamFilesTree personalCommit(PersonalFilesTreeVo personalFilesTreeVo, Team team);

    TeamFilesTree nameRechecking(String realName, String parentId, String suffix);

    /**
     * 插入一条新数据。
     */
    TeamFilesTreeDto insert(String parentId,String realName,String teamId,String type);
    int updateById(TeamFilesTreeDto resources);
    int removeById(Long id);
    int removeByIds(Set<Long> ids);


    void downloadFile(String id,String fileName, HttpServletResponse response);

    String createTemplate(Long templateId, Long parentFolderId, String folderName, LoginUser user);

    void setParentNodeSize(String parentId, Long size, int addAndMinus);

    List<TeamToEnterpriseDto> createFolder(String filesId,String parentId);

    TeamFilesTreeDto createFileFromTemplate(Long templateId, Long parentFolderId, String fileName, String type,String tempType);

    R topMark(FilesTreeTop top);

    TeamFilesTreeDto selectTree(TeamFilesTreeQueryParam query);

    TableDataInfo<TeamFilesTreeDto> selectTreePage(TeamFilesTreeQueryParam query, Pageable pageable);

    List<TeamFilesTreeDto> wFlowCopyTree(List<Long> treeNodeIdsList);

    List<DataItem> getAllParentId(String parentId);

    int selectByIdTreePageInfo(String treeId, String parentId, int size, List<String> sort, List<TeamRelevanceRole> relevanceRole);

    TableDataInfo<FilesTree> SearchTeamFileTreePage(SearchFilesInfoDto infoDto, List<TeamRelevanceRole> relevanceRole, Pageable pageable);

    List<TeamFilesTree> nameRecheckingVerifyData(String parentId);

    void createFileToEs(Long id);

    List<FilesTree> selectTreeByDownloadFile(List<String> idList, Long userId);

    TeamFilesTree createFile(RemoteFilesUpload uploadDto, String parentId, String fileName, String remarks, Object o, String string, String username, LoginUser user);

    List<RemoteFilesDownload> teamDownloadFile(List<String> idList, Long userId);

}
